<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    var arr1 = [2,6,3,4,7,8,1];
    for(var i = 0 ;i <arr1.length-1;i++){
        for(var j = 0 ;j<arr1.length-i-1;j++){
            if(arr1[j]>arr1[j+1]){
                var c = arr1[j];
                arr1[j]=arr1[j+1];
                arr1[j+1]=c;
            }
        }
    }
    console.log(arr1);

    function str(arr){
        for(var i = 0 ; i<arr.length-1;i++){
            for(var j = 0 ; j<arr.length-1-i;j++){
                if(arr[j]<arr[j+1]){
                    var t= arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=t;
                }
            }
        }
        console.log(arr);
        //arr[arr.length-1]：最小值
    }
    str([3,5,4,1,8,5,6]);
</script>